package leetCode;

import java.util.LinkedList;
import java.util.Queue;

public class T225 {

}
class MyStack {
    Queue<Integer>queue0;
    Queue<Integer>queue1;
    public MyStack() {
        queue0=new LinkedList<>();
        queue1=new LinkedList<>();
    }

    public void push(int x) {
        //将0的所有元素插入到1中
        if (queue0.isEmpty()){
            queue0.offer(x);
            while (!queue1.isEmpty()){
                queue0.offer(queue1.poll());
            }
        }else {
            queue1.offer(x);
            while (!queue0.isEmpty()){
                queue1.offer(queue0.poll());
            }
        }

        //将x插入0，再将列1中所有的元素插回0

    }

    public int pop() {
        //弹出列0的元素

        return queue0.isEmpty()?queue1.poll():queue0.poll();
    }

    public int top() {
        //展示列0的元素
        return queue0.isEmpty()?queue1.peek():queue0.peek();
    }

    public boolean empty() {
        //判断列0是否为空
        return queue0.isEmpty()&&queue1.isEmpty();
    }
}
